<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<if condition="(I('request.disp') eq 1)">
				<li><a href="{:U('Examine/loan_third')}">第三方催缴列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id'],'disp'=>1))}">{$order.name}详情</a></li>
			<elseif condition="(I('request.disp') eq 'm1')"/>
				<li><a href="{:U('Examine/loan_overdue_m1')}">逾期M1列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id'],'disp'=>'m1'))}">{$order.name}详情</a></li>
			<elseif condition="(I('request.disp') eq 'm2')"/>
				<li><a href="{:U('Examine/loan_overdue_m2')}">逾期M2列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id'],'disp'=>'m2'))}">{$order.name}详情</a></li>	
			<else />
				<li><a href="{:U('Examine/loan_overdue')}">逾期列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id']))}">{$order.name}详情</a></li>
			</if>
			<li class="active"><a>逾期还款审核</a></li>
		</ul>
        <form class="form-horizontal js-ajax-form" method="post">
			<fieldset>
				<div class="tabbable">
					<div class="tab-content">
						
							<fieldset>
								<div class="control-group">
									<label class="control-label">姓名</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.name}&nbsp&nbsp&nbsp&nbsp{$order['account_status']?'[已认证]':'[未认证]'}</label>
										<input type="hidden" name="options[id]" value="{$order.id}">
										<input type="hidden" name="options[user_id]" value="{$order.user_id}">
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">手机号码</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.mobile}</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">借款金额</label>
									<div class="controls">
									<label class="control-label" style="width:auto">{$order.amount}元</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">借款天数</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.loan_day}天</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">放款日</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.loan_time}</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">分期数</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.stages}期</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">咨询费</label>
									<div class="controls">
									<label class="control-label" style="width:auto">{$order.interest}元</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">审核费</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.examine}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">顾问费</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.consulting}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">到期应还</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.loan_amount}元</label></div>
								</div>
								<br />
								<if condition="(I('request.disp') neq 1)">
								<div class="control-group">
									<label class="control-label">分期详情</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>期数</th>
												<th>到期时间</th>
												<th>借款状态</th>
												<th>分期金额</th>
												<th>审核操作</th>
											</tr>
											<php>$haikuanjine=0;
													$qishu=0;
													$daoqi=array();
											</php>
											<php>$rei=0;$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款')</php>
											<foreach name="sub" item="vo">
												<tr>
													<php>$stag=substr($vo['stages'], 1);$stages=substr($vo['stages'],0, 1);</php>
													<td>第{$stages}期
													<if condition="$stag">第{$stag}次续期
													</if>
													<td>{$vo.endtime}</td>
													<td>{$stu_type[$vo['status']]}</td>
													<td>{$vo.amount}</td>
													<td>
													<php>
														if($vo['status']==3){
															$haikuanjine+=$vo['amount'];
														}
														if($vo['status']==3){
															$daoqi[]=substr($vo['stages'],0,1);
															if(empty($qishu)){
																$qishu=$vo['stages'];
															}
														}
													</php>
													</td>
												</tr>
											</foreach>
												<tr>
													<td>共{$order.stages}期</td>
													<td>{$order.loan_day}天</td>
													<td>{$stu_type[$order['status']]}</td>
													<td>{$order.amount}</td>
													<td></td>
												</tr>
										</table>
									</label>
									</div>
									<input type="hidden" name="options[stages]" value="{$qishu}">
								</div>
								<div class="control-group">
									<label class="control-label">续期详情</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
									<if condition="(empty($renewal))">
										暂无记录
									<else/>
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>借款编号</th>
												<th>续期时间</th>
												<th>完结时间</th>
												<th>续期金额</th>
												<th>审核备注</th>
												<th>状态</th>
												<th>审核人</th>
											</tr>
											<foreach name="renewal" item="vo">
												<tr>
													<td>{$vo.order_id}</td>
													<td>{$vo.renewal}</td>
													<td>{$vo.endtime}</td>
													<td>{$vo.amount}</td>
													<td>{$vo.message}</td>
													<td>{$vo['status']==1?'审核成功':'审核失败'}</td>
													<td>{$lastuser[$vo['lastuser_id']]|default='系统'}</td>
												</tr>
											</foreach>
										</table>
									</if>
									</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">审核记录</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
									<if condition="(empty($logs))">
										暂无记录
									<else/>
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>审核类型</th>
												<th>审核时间</th>
												<th>审核备注</th>
												<th>金额</th>
												<th>实收金额<br/>(不含逾期费)</th>
												<th>实收逾期费</th>
												<th>微信实收</th>
												<th>支付宝实收</th>
												<th>银行实收</th>
												<th>审核操作</th>
												<th>审核人</th>
												<th>收款人</th>
											</tr>
											<php>$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款');
											$stu_ty=array('0'=>'用户审核','1'=>'订单审核','2'=>'订单审核','3'=>'续期审核','4'=>'逾期还款(本金)','5'=>'逾期还款','6'=>'订单审核','7'=>'客户还款');
											</php>
											<foreach name="logs" item="vo">
												<tr>
													<php>
													if($order['stages']==1){
															if($vo['types']==7 || $vo['types']==4){
																	if($vo['status']){
																		$haikuanjine-=$vo['amount'];
																	}
																}
													}else{
														if(in_array(substr($vo['stages'],0,1),$daoqi)){
																if($vo['types']==7 || $vo['types']==4){
																	if($vo['status']){
																		$haikuanjine-=$vo['amount'];
																	}
																}
														}
													}	
													</php>
													<td>{$stu_ty[$vo['types']]}</td>
													<td>{$vo.crtime}</td>
													<td>{$vo.message}</td>
													<td>{$vo.amount}</td>
													<td>{$vo.real_amount|default='0.00'}</td>
													<td>{$vo.overdue_amount|default='0.00'}</td>
													<td>{$vo.wechat_amount}</td>
													<td>{$vo.alipay_amount}</td>
													<td>{$vo.bank_amount}</td>
													<td>{$vo['status']?'审核成功':'审核失败'}</td>
													<td>{$lastuser[$vo['examine_id']]|default='系统'}</td>
													<td>{$lastuser[$vo['payee']]}</td>
												</tr>
											</foreach>
										</table>
									</if>
									</label>
									</div>
								</div>
								</if>
								<div class="control-group">
									<label class="control-label">还款时间</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.endtime}</label></div>
								</div>
								<php>$overdue=check_amount_user_overdue($order['user_id']);</php>
								<div class="control-group">
									<label class="control-label">逾期天数</label>
									<div class="controls"><label class="control-label" style="width:auto">{$overdue.over_day|default='0'}天</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">逾期金额</label>
									<php>$over_amount=yu_amount($order['user_id']);</php>
									<div class="controls"><label class="control-label" style="width:auto">{$over_amount|default='0'}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">还款总金额</label>
									<php>$haikuanjine=$over_amount+$haikuanjine</php>
									<div class="controls"><label class="control-label" style="width:auto">{$haikuanjine|default='0'}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">账号余额</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.deposit|default=0}元</label></div>
								</div>
								<if condition="(I('request.disp') neq 1)">
								<div class="control-group">
									<label class="control-label">审核备注</label>
									<div class="controls">
										<textarea name="options[message]" rows="4" cols="30"></textarea>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label"><b style="color:red;">* </b><strong>借条金额</strong></label>
									<div class="controls">
										<input name="options[exam_amount]" id='amounts' type="text"  class="just_can_number" value="0" /><span style="color:#b4b4b4;"> 备注：系统应收</span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">实收借条金额</label>
									<div class="controls">
										<input type="text" name="options[real_amount]" class="just_can_number" size="11"  placeholder="请输入数字" /><span style="color:#b4b4b4;"> 备注：不含逾期费</span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">实收逾期费</label>
									<div class="controls">
										<input type="text" name="options[overdue_amount]" class="just_can_number" size="11"  placeholder="请输入数字" /><span style="color: #b4b4b4">&nbsp;备注：请输入收到的逾期费(没有则不用填或填0)，小心忘记了</span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">
										<b style="color:red;">* </b><strong>收款方式</strong>
									</label>
									<div class="controls">
										<select id="pay_ways">
											<!--<option value="0">请选择一种收款方式</option>-->
											<option value="1">微信</option>
											<option value="2">支付宝</option>
											<option value="3">银行</option>
										</select>
										<button id="pay_add" type="button" class="btn btn-success">添加</button>
										<button  id="pay_del" style="display: none;" type="button" class="btn btn-danger">减少</button>
									</div>
									<script>
                                        $(function(){
                                            var wechat_amount = $("#wechat_amount");
                                            var alipay_amount = $("#alipay_amount");
                                            var bank_amount = $("#bank_amount");
                                            //增加
                                            $('#pay_add').click(function(){
                                                var storges = [1,2,3];
                                                for (var i in storges) {
                                                    var obj = $('.pay_'+storges[i]);
                                                    var dis = obj.css('display');
                                                    if(dis === 'none'){
                                                        obj.show();
                                                        break;
                                                    }
                                                }
                                                var pay_1 = $('.pay_'+storges[0]);
                                                var pay_2 = $('.pay_'+storges[1]);
                                                var pay_3 = $('.pay_'+storges[2]);
                                                var dis_1 = pay_1.css('display');
                                                var dis_2 = pay_2.css('display');
                                                var dis_3 = pay_3.css('display');
                                                var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                                var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                                var pay_del = $('#pay_del');
                                                if(true === flag1){
                                                    $(this).hide();
                                                    pay_del.show();
                                                }else if(false === flag1 && false === flag2){
                                                    $(this).show();
                                                    pay_del.show();
                                                }else if(false === flag1 && true === flag2){
                                                    $(this).show();
                                                    pay_del.hide();
                                                }
                                            });
                                            //减少
                                            $('#pay_del').click(function(){
                                                var storges = [3,2,1];
                                                for (var i in storges) {
                                                    var obj = $('.pay_'+storges[i]);
                                                    var dis = obj.css('display');
                                                    if(dis === 'block'){
                                                        obj.hide();
                                                        obj.find('input').val('');//凡是隐藏了的，必须值也清空
                                                        break;
                                                    }
                                                }
                                                var pay_3 = $('.pay_'+storges[0]);
                                                var pay_2 = $('.pay_'+storges[1]);
                                                var pay_1 = $('.pay_'+storges[2]);
                                                var dis_1 = pay_1.css('display');
                                                var dis_2 = pay_2.css('display');
                                                var dis_3 = pay_3.css('display');
                                                var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                                var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                                var pay_add = $('#pay_add');
                                                if(true === flag1){
                                                    $(this).show();
                                                    pay_add.hide();
                                                }else if(false === flag1 && false === flag2){
                                                    var flag3 = (dis_1 === 'block' && dis_2 === 'none' && dis_3 === 'none');
                                                    if(flag3){
                                                        $(this).hide();
                                                        pay_add.show();
                                                    }else{
                                                        $(this).show();
                                                        pay_add.show();
                                                    }
                                                }else if(false === flag1 && true === flag2){
                                                    $(this).hide();
                                                    pay_add.show();
                                                }

                                            });
                                            //下拉
                                            $('#pay_ways').change(function(){
                                                $('#pay_add').show();
                                                $('#pay_del').hide();
                                                if(0 !== parseInt($(this).val())){
                                                    switch(parseInt($(this).val())){
                                                        case 1:
                                                            wechat_amount.show();
                                                            alipay_amount.hide();
                                                            bank_amount.hide();
                                                            alipay_amount.find('input').val('');
                                                            bank_amount.find('input').val('');
                                                            break;
                                                        case 2:
                                                            wechat_amount.hide();
                                                            alipay_amount.show();
                                                            bank_amount.hide();
                                                            wechat_amount.find('input').val('');
                                                            bank_amount.find('input').val('');
                                                            break;
                                                        case 3:
                                                            wechat_amount.hide();
                                                            alipay_amount.hide();
                                                            wechat_amount.find('input').val('');
                                                            alipay_amount.find('input').val('');
                                                            bank_amount.show();
                                                            break;
                                                    }
                                                }else{
                                                    wechat_amount.hide();
                                                    alipay_amount.hide();
                                                    bank_amount.hide();
                                                }
                                            });
                                        });
									</script>
								</div>
								<div class="control-group pay_1" id="wechat_amount" style="display: block;">
									<label class="control-label">微信实收</label>
									<div class="controls">
										<input type="text" name="options[wechat_amount]" class="just_can_number" size="11"  placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group pay_2" id="alipay_amount" style="display: none;">
									<label class="control-label">支付宝实收</label>
									<div class="controls">
										<input type="text" name="options[alipay_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group pay_3" id="bank_amount" style="display: none;">
									<label class="control-label">银行实收</label>
									<div class="controls">
										<input type="text" name="options[bank_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">选择收款人员</label>
									<div class="controls">
										<select name="options[payee]">
											<option value="{:get_current_admin_id()}">自己</option>
											<foreach name="daihou" item="vo">
												<option value="{$vo.id}">{$vo.user_login}</option>
											</foreach>
										</select>
									</div>
								</div>
								</if>
							</fieldset>
					</div>
				</div>
<if condition="(I('request.disp') neq 1)">
				<div class="form-actions">
					<button class="btn btn-primary js-ajax-submit" type="submit" data-types='1' data-action="{:U('Examine/overdue_exam_act',array('display'=>1,'disp'=>I('get.disp',0)))}" data-msg='审核确认?' data-subcheck="true">审核确认</button>
					<a class="btn btn-primary js-ajax-submit"  href="{:U('Examine/loan_overdue')}">返回</a>
				</div>
</if>
			</fieldset>
		</form>
		
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
</body>
<script type="text/javascript">
	var ajaxForm_list = $('form.js-ajax-form');
	if (ajaxForm_list.length) {
	    Wind.use('ajaxForm', 'artDialog', function () {
			
	        $('button.js-ajax-submit').bind('click', function (e) {

	            e.preventDefault();
	            /*var btn = $(this).find('button.js-ajax-submit'),
						form = $(this);*/
	            var btn = $(this),
	                form = btn.parents('form.js-ajax-form');
				//var a=document.getElementsByName("options[status][1]");
				<!-- var stages={$order.stages}; -->
				<!-- for(i=1;i<=stages;i++){ -->
					<!-- var a=$("input:radio[name='options[status]["+i+"]']:checked ").val(); -->
					<!-- window.console.log(a); -->
				<!-- } -->
				
	            //批量操作 判断选项
	            if (btn.data('subcheck')) {
	                btn.parent().find('span').remove();
					var msg = btn.data('msg');
					if (msg) {
						art.dialog({
							id: 'warning',
							icon: 'warning',
							content: btn.data('msg'),
							cancelVal: "{:L('CLOSE')}",
							cancel: function () {
								
							},
							button :[ {
											name : "{:L('OK')}",
											callback:function(){
												ajaxSubmit(btn.data('types'));
											},
											focus : true
									} ]
						});
					} else {
						btn.data('subcheck', false);
						btn.click();
					}
	                return false;
	            }
	        });
	
	    });
	}
	function ajaxSubmit(type){
			var btn = $('button.js-ajax-submit'),
			form = btn.parents('form.js-ajax-form');
			form.ajaxSubmit({
	                url: type ? btn.data('action') : form.attr('action'),
	                //按钮上是否自定义提交地址(多按钮情况)
	                dataType: 'json',
	                beforeSubmit: function (arr, $form, options) {
						var amounts=document.getElementById('amounts').value;
						if({$haikuanjine}<amounts){
							alert('请输入正确的金额');
							return false;
						}
						var tx=type ? '审核通过' : '审核不通过';
	                    //按钮文案、状态修改
	                    btn.text(tx + '中...').attr('disabled', true).addClass('disabled');
	                },
	                success: function (data, statusText, xhr, $form) {
	                    //按钮文案、状态修改
	                    btn.removeClass('disabled').parent().find('span').remove();
	
	                    if (data.state === 'success') {
	                        $('<span class="tips_success">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('slow').delay(1000).fadeOut(function () {
	                            if (data.referer) {
	                                //返回带跳转地址
	                                if (window.parent.art) {
	                                    //iframe弹出页
	                                    window.parent.location.href = data.referer;
	                                } else {
	                                    window.location.href = data.referer;
	                                }
	                            } else {
	                                if (window.parent.art) {
	                                    reloadPage(window.parent);
	                                } else {
	                                    //刷新当前页
	                                    reloadPage(window);
	                                }
	                            }
	                        });
	                    } else if (data.state === 'fail') {
	                        $('<span class="tips_error">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('fast');

	                        btn.text('手工确认还款调整').removeProp('disabled').removeClass('disabled');
	                    }
	                }
	            });
	}


	</script>
<script>
    $(function(){
        $('.just_can_number').keyup(function(){
        	var obj = this;
            obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        });
    });
</script>
</html>